home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / misc_pto / mwpetz06 / digclock.cpp < prev    next >
C/C++ Source or Header  |  1991-05-15  |  2KB  |  63 lines

  1. #include "digclock.hpp"
  2.  
  3. clockPane::clockPane(Window *w): TextPane(w) {
  4.     setSizeWithParent();
  5.  
  6.     String cName("intl");
  7.     iDate=GetProfileInt(cName,"iDate",0);
  8.     iTime=GetProfileInt(cName,"iTime",0);
  9.     GetProfileString(cName,"sDate","/", sDate,    2);
  10.     GetProfileString(cName,"sTime",":", sTime,    2);
  11.     GetProfileString(cName,"s1159","AM",sAMPM [0],5);
  12.     GetProfileString(cName,"s2359","PM",sAMPM [1],5);
  13.  
  14.     create(0,SW_SHOWNOACTIVATE);
  15.     tim=new Timer(1,this,(TimerProc)clockPane::tick);
  16. }
  17.  
  18. clockPane::~clockPane() {
  19.     delete tim;
  20. }
  21.  
  22. void clockPane::tick() {
  23.     static char szWday[] = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat" ;
  24.     char        cBuffer[40] ;
  25.     long        lTime ;
  26.     RECT        rect ;
  27.     short       nLength ;
  28.     struct tm   *datetime ;
  29.     
  30.     time(&lTime) ;
  31.     datetime=localtime(&lTime) ;
  32.     
  33.     nLength = wsprintf(cBuffer,"  %s  %d%s%02d%s%02d  \n",
  34.         (LPSTR) szWday + 4 * WDAY,
  35.         iDate==1 ? MDAY :iDate==2 ? YEAR :MONTH,sDate,
  36.         iDate==1 ? MONTH:iDate==2 ? MONTH:MDAY,sDate,
  37.         iDate==1 ? YEAR :iDate==2 ? MDAY :YEAR);
  38.  
  39.      if (iTime==1)
  40.           nLength+=wsprintf(cBuffer + nLength, "  %02d%s%02d%s%02d  ",
  41.                                HOUR, (LPSTR) sTime, MIN, (LPSTR) sTime, SEC) ;
  42.      else
  43.           nLength+=wsprintf(cBuffer + nLength, "  %d%s%02d%s%02d %s  ",
  44.                                (HOUR % 12) ? (HOUR % 12) : 12,
  45.                                (LPSTR) sTime, MIN, (LPSTR) sTime, SEC,
  46.                                (LPSTR) sAMPM [HOUR / 12]) ;
  47.  
  48.     moveTo(0,0);                
  49.     printf(cBuffer);
  50. }
  51.  
  52. MainFrame::MainFrame() :AppFrame("zApp DigClock") {
  53.     create(0,SW_SHOWNOACTIVATE);
  54.     p=new clockPane(this);
  55. }
  56.  
  57. void App::main() {
  58.     MainFrame *p=new MainFrame();
  59.     app->go();
  60.     delete p;
  61. }
  62.  
  63.